const userModel = require('../models/user.js')

exports.get = async function (req, res, next) {
	try {
		const {email = '', nickname = ''} = req.query
		if (email) {
			const user = await userModel.getUserByCondition('email', email)
			res.status(200).json({user})
		} else if (nickname) {
			const user = await userModel.getUserByCondition('nickname', nickname)
			res.status(200).json({user})
		}
	} catch(err) {
		next(err)
	}
}

exports.create = async function (req, res, next) {
	const body = req.body
	try {
		const id = await userModel.addUser(body)
		const user = await userModel.getUserByCondition('id', id)
		res.status(200).json({user})
	} catch(err) {
		next(err)
	}
}

exports.update = function (req, res, next) {

}

exports.destroy = function (req, res, next) {

}
